<template>
  <div class="audited">
    <div class="section">
      <h3>待审核</h3>
      <SearchItem @searchList="searchData" :type="2"></SearchItem>
    </div>
    <el-table
      :height="tabHeight"
      border
      style="width: 100%"
      align="center"
      :data="tableData"
      @selection-change="selectTable"
      v-loading="loading"
    >
      <el-table-column type="selection" width="35"></el-table-column>
      <el-table-column prop="roId" label="ID" width="145"></el-table-column>
      <el-table-column prop="username" label="用户名" width="60"></el-table-column>
      <el-table-column prop="cpName" label="所属CP" width="60"></el-table-column>
      <el-table-column prop="gameName" label="游戏名" width="90"></el-table-column>
      <el-table-column prop="serverName" label="区服" width="90"></el-table-column>
      <el-table-column prop="roleName" label="角色名" width="110"></el-table-column>
      <el-table-column prop="roleId" label="角色ID"></el-table-column>
      <el-table-column prop="amount" label="申请金额" width="65"></el-table-column>
      <el-table-column prop="amountTotal" label="今日总金额" width="75"></el-table-column>
      <el-table-column prop="applyTime" label="申请时间"></el-table-column>
      <el-table-column prop="payTime" label="充值时间"></el-table-column>
      <el-table-column label="返利信息" width="60">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showdialog(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="玩家备注" width="60" prop="remark">
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="showNotes(scope.row)"
            size="small"
            v-show="scope.row.remark"
          >查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="明细" width="40">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="showdetail(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="success" plain size="mini" @click="auditApproval(scope.row)">通过</el-button>
          <el-button type="danger" plain size="mini" @click="rejectNotes(scope.row)">驳回</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="bottom">
      <!-- 将分页器作为子组件引入 -->
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="pagenationData.currentPage"
        :page-size="pagenationData.pageSize"
        :total="pagenationData.pageTotal"
        background
        layout="prev, pager, next"
        prev-text="上一页"
        next-text="下一页"
      ></el-pagination>
      <el-button type="primary" @click="passThrough">一键通过</el-button>
    </div>
    <!-- 查看返利信息 -->
    <ShowRebateDialog
      v-if="showRebateDialog.show"
      :isShow="showRebateDialog.show"
      :dialogRow="showRebateDialog.dialogRow"
      @closeDialog="hideRebateDialog"
    ></ShowRebateDialog>
    <!-- 通过备注 -->
    <RemarkDialog
      v-if="remarkDialog.show"
      :isShow="remarkDialog.show"
      :rowId="remarkDialog.rowId"
      @passRemark="passRemark"
      @closeDialog="closeremarkDialog"
    ></RemarkDialog>
    <!-- 驳回备注 -->
    <RejectDialog
      v-if="rejectDialog.show"
      :isShow="rejectDialog.show"
      :rowId="rejectDialog.rowId"
      @rejectRemark="rejectRemark"
      @closeDialog="closerejectDialog"
    ></RejectDialog>
    <!-- 返利明细 -->
    <DetailDialog
      v-if="detailDialog.show"
      :isShow="detailDialog.show"
      :dialogRow="detailDialog.dialogRow"
      @closeDialog="hideDetailDialog"
    ></DetailDialog>
  </div>
</template>
<script>
import { mapGetters } from "vuex";

import SearchItem from "@/components/search/SearchItem";
import RemarkDialog from "@/components/dialog/RemarkDialog";
import ShowRebateDialog from "@/components/dialog/ShowRebateDialog";
import RejectDialog from "@/components/dialog/RejectDialog";
import DetailDialog from "@/components/dialog/DetailDialog";

import * as mutils from "@/utils/mUtils";
import {
  getauditedData,
  onekeyPass,
  rejectInline,
  passInline,
  showrebateDetail
} from "@/api/data";
export default {
  name: "audited",
  inject: ["reload"],
  components: {
    SearchItem,
    RemarkDialog,
    ShowRebateDialog,
    RejectDialog,
    DetailDialog
  },
  data() {
    return {
      tabHeight: window.innerHeight - 200,
      multipleSelection: [], //复选框选中
      loading: true,
      formData: {
        //搜索条件
        playAccount: "",
        gameName: ""
      },
      pagenationData: {
        pageTotal: 0,
        currentPage: 1,
        pageSize: 20
      },
      remarkDialog: {
        show: false,
        rowId: 0
      },
      rejectDialog: {
        show: false,
        rowId: 0
      },
      showRebateDialog: {
        show: false,
        dialogRow: {}
      },
      detailDialog: {
        show: false,
        dialogRow: []
      },
      tableData: [],
      pageData: {
        page: 1,
        limit: 20
      },
      search: {}
    };
  },
  mounted() {
    this.getauditedData();
  },
  methods: {
    searchData(search) {
      this.search = search;
      this.search.page = 1;
      this.pagenationData.currentPage = 1;
      this.searchList();
    },
    // 搜索数据
    searchList() {
      this.loading = true;
      const para = Object.assign({}, this.search);
      getauditedData(para).then(res => {
        this.loading = false;
        this.pagenationData.pageTotal = res.data.count;
        this.tableData = res.data.list;
      });
    },
    // 获取待审核数据
    getauditedData() {
      const para = Object.assign({}, this.pageData);
      getauditedData(para).then(res => {
        this.loading = false;
        this.pagenationData.pageTotal = res.data.count;
        this.tableData = res.data.list;
      });
    },
    showdialog(row) {
      //返利信息弹框显示
      this.showRebateDialog.dialogRow = row; //将行内信息存储，方便弹框显示
      this.showRebateDialog.show = true;
    },

    showNotes(row) {
      //查看玩家备注
      this.$alert(row.remark, "玩家备注", {
        confirmButtonText: "确定",
        center: true
      });
    },
    showdetail(row) {
      let roId = {
        roId: row.roId
      };
      showrebateDetail(roId).then(res => {
        this.detailDialog.dialogRow = res.data.list;
        this.detailDialog.show = true;
      });
    },
    // 显示通过备注弹框
    auditApproval(row) {
      this.remarkDialog.rowId = row.roId;
      this.remarkDialog.show = true;
    },
    // 显示驳回备注
    rejectNotes(row) {
      this.rejectDialog.rowId = row.roId;
      this.rejectDialog.show = true;
    },
    // 单个驳回
    rejectRemark(data) {
      rejectInline(data).then(res => {
        let result = res.data.result;
        if (result == 2) {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          setTimeout(() => {
            this.reload();
          }, 20);
        } else {
          this.$message({
            type: "warning",
            message: "操作失败"
          });
        }
      });
    },
    closerejectDialog() {
      this.rejectDialog.show = false;
    },
    passThrough() {
      //一键通过
      let len = this.multipleSelection.length;
      if (len === 0) {
        this.$message({
          type: "warning",
          message: "请至少选择一项！"
        });
      } else {
        this.$confirm(`确定一键审核选中的 ${len} 条数据吗？`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          var roIdArr = [];
          this.multipleSelection.forEach(item => {
            roIdArr.push(item.roId);
          });
          let roIdStr = roIdArr.join(",");
          onekeyPass({ roIds: roIdStr }).then(res => {
            let result = res.data.result;
            if (result == 2) {
              this.$message({
                type: "success",
                message: "操作成功"
              });
              setTimeout(() => {
                this.reload();
              }, 20);
            } else {
              this.$message({
                type: "warning",
                message: "操作失败"
              });
            }
          });
        });
      }
    },

    hideRebateDialog() {
      //关闭查看返利
      this.showRebateDialog.show = false;
    },
    hideDetailDialog() {
      this.detailDialog.show = false;
    },
    // 当用户手动勾选数据行的 Checkbox 时触发的事件
    selectTable(val, row) {
      this.multipleSelection = val;
    },
    // 上下分页
    handleCurrentChange(val) {
      this.pageData.page = val;
      this.search.page = val;
      this.searchList();
    },
    // 单个审核通过
    passRemark(data) {
      passInline(data).then(res => {
        let result = res.data.result;
        if (result == 2) {
          this.$message({
            type: "success",
            message: "操作成功"
          });
          setTimeout(() => {
            this.reload();
          }, 20);
        } else {
          this.$message({
            type: "warning",
            message: "操作失败"
          });
        }
      });
    },
    closeremarkDialog() {
      this.remarkDialog.show = false;
    }
  }
};
</script>
<style lang="scss">
.audited {
  .el-button.el-button--success,
  .el-button.el-button--danger {
    padding: 5px 7px;
  }
  .el-button + .el-button {
    margin-left: 5px;
  }
  .el-button:active {
    border-color: transparent;
  }
  .sendtoCP {
    background: #4ad991;
    border-color: #4ad991;
    width: 110px;
  }
}
.el-message-box--center .el-message-box__header {
  padding-top: 20px;
}
.el-message-box--center {
  padding-bottom: 20px;
}
.el-message-box__btns {
  margin-top: 10px;
}
</style>



